function [net_result_path, bFound] = getResultPath(net, solv, cmd, Train, flag)
% set net_result_path;

%% get a clean version of net and solv
Train = setFiles(Train);

net.file = mycaffe.getFolderFile(net.file);

if isfield(cmd, 'caffe')
	caffe = cmd.caffe;
elseif isfield(cmd, 'caffe_version')
	caffe = mycaffe.caffe_cmd(cmd.caffe_version);
end

hFunc = @ mycaffe.net.rmUnnecessaryFields;

%%
suffix = '';
prefix = net.name;

if isfield(cmd, 'weights')
    suffix = ']';
    solv.weights = mycaffe.net.rmExpPath(cmd.weights, net.result_path);
    [~, net_name0] = fileparts(fileparts(fileparts(cmd.weights)));
    prefix = sprintf('[%s]-tuning2-[%s', net_name0, net.name);
elseif isfield(cmd, 'snapshot')
    suffix = ']';
    solv.snapshot = mycaffe.net.rmExpPath(cmd.snapshot, net.result_path);
    net_result_path0 = fileparts(fileparts(cmd.snapshot));
    bFound = myinput.searchDataByParam(net_result_path0, 'st.mat', '', hFunc, Train, net, solv, caffe);
    if bFound
        net_result_path = net_result_path0;
        return
    end
    
    [~, net_name0] = fileparts(net_result_path0);
    prefix = sprintf('[%s]-snapshot2-[%s', net_name0, net.name);
end

net_result_path = fullfile(net.result_path, [prefix '*' suffix]);
if isempty(flag)
    [bFound, net_result_path] = myinput.searchDataByParam(net_result_path, 'st.mat', '', hFunc, Train, net, solv, caffe);
else
    [bFound, net_result_path] = myinput.searchDataByParam(net_result_path, 'st.mat', '', hFunc, Train, net, solv, caffe, flag);
end

function stSet = setFiles(stSet)

if ~isfield(stSet, 'files')
    stSet.files = '';
    return
end

stSet.files = mycaffe.getFolderFile(stSet.files);
